//
//  UIColor+YW_Color.swift
//  demo02
//
//  Created by 陈友文 on 2021/1/27.
//

import UIKit


extension UIColor{
    /// 设置随机颜色
    class func randomColor() -> UIColor
    {
        let color: UIColor = UIColor.init(red: (((CGFloat)((arc4random() % 256)) / 255.0)), green: (((CGFloat)((arc4random() % 256)) / 255.0)), blue: (((CGFloat)((arc4random() % 256)) / 255.0)), alpha: 1.0);
        return color;
    }
    class func RGBColor(R:CGFloat, G:CGFloat, B:CGFloat, alpha:CGFloat) -> UIColor
    {
        let color = UIColor.init(red: (R / 255.0), green: (G / 255.0), blue: (B / 255.0), alpha: alpha);
        return color;
    }
    /// 设置颜色与透明度 示例：UIColorHEX_Alpha(0x26A7E8, 0.5)
    class func HEXColor(value:UInt32, alpha:CGFloat) -> UIColor
    {
        let color = UIColor.init(red: (((CGFloat)((value & 0xFF0000) >> 16)) / 255.0), green: (((CGFloat)((value & 0xFF0000) >> 16)) / 255.0), blue: (((CGFloat)((value & 0xFF0000) >> 16)) / 255.0), alpha: alpha)
        return color
    }
    /// 设置颜色（RGB：0.0~255.0） 示例：UIColorRGB(100, 100, 100)
    class func UIColorRGB(R:CGFloat, G:CGFloat, B:CGFloat) -> UIColor
    {
        return RGBColor(R: R, G: G, B: B, alpha: 1.0);
    }
    
    /// 设置颜色 示例：UIColorHex(0x26A7E8)
    class func UIColorHex(value:UInt32) -> UIColor
    {
        return HEXColor(value: value, alpha: 1.0);
    }
    
    class func aisaiYellowColor() -> UIColor{
        return RGBColor(R: 255, G: 242, B: 119, alpha: 1)
    }
    
    class func aisaiGrayColor() -> UIColor{
        return RGBColor(R: 220, G: 220, B: 220, alpha: 1)
    }
    class func aisai78GrayColor() -> UIColor{
        return RGBColor(R: 78, G: 78, B: 78, alpha: 1)
    }
    class func aisai37GrayColor() -> UIColor{
        return RGBColor(R: 37, G: 37, B: 37, alpha: 1)
    }
    class func imageWithColor(color:UIColor)->UIImage{
        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context!.setFillColor(color.cgColor)
        context!.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
    }
}
